﻿<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <title>会员卡订单</title>
    <link href="/style/rightdirectory.css" rel="stylesheet" />
    <script src="/script/config.js"></script>
    <style>
        th {
            text-align: center;
        }

        td {
            text-align: center;
        }
    </style>
</head>
<body>
    <div class="view-page">
        <!--搜索区域-->
        <div class="view-search inline">
            <div class="form-inline">
                <div class="form-group col-sm-2">
                    <div class="input-group">
                        <span class="input-group-addon">手机号码</span>
                        <input id="query" type="text" class="form-control" data-form="Phone" placeholder="手机号码">
                    </div>
                </div>

                <div class="form-group col-sm-1">
                    <button type="button" id="btn-search" class="btn btn-primary">
                        <i class="fa fa-search"></i> 搜索
                    </button>
                </div>
            </div>
        </div>

        <div class="view-data" id="upgrade">
            <table id="table" class="table table-bordered table-hover" data-post="">
                <thead>
                    <tr>
                        <th>
                            ID
                        </th>
                        <th>订单号</th>
                        <th>订单状态</th>
                        <th>供货商名称</th>
                        <th>支付类型</th>
                        <th>物流公司名称</th>
                        <th>物流公司编码</th>
                        <th>物流单号</th>
                        <th>收货真实姓名</th>
                        <th>手机号码</th>
                        <th>产品数量</th>
                        <th>原价总额</th>
                        <th>支付总额</th>
                        <th>创建时间</th>
                        <th>是否发货</th>
                    </tr>
                </thead>
                <tbody></tbody>
            </table>
            <!--分页条 默认选择id=list-page元素-->
            <div id="list-page" class="view-pagination-page"></div>
        </div>
    </div>


</body>

</html>

<link href="/script/valid/css/tr.css" rel="stylesheet" /><!--判断如：PlatformName格式-->
<script src="/script/valid/form-valid.js?v=2018"></script>


<script type="text/html" id="tp-table">
    {{each list d}}
    <tr>
        <td>
            {{d.Id}}
        </td>
        <td><a class="detail" href="javascript:;" onclick="openDetail('{{d.OrderNo}}')">{{d.OrderNo}}</a></td>
        {{if d.Status==1}}
        <td>待付款</td>
        {{else if d.Status==2}}
        <td>待发货</td>
        {{else if d.Status==3}}
        <td>待收货</td>
        {{else if d.Status==4}}
        <td>待评价</td>
        {{else if d.Status==5}}
        <td>已完成</td>
        {{/if}}
        <td>{{d.SupplierName}}</td>
        <td>{{d.PayName}}</td>
        <td>{{d.LogisticsName}}</td>
        <td>{{d.LogisticsCode}}</td>
        <td>{{d.LogisticsNo}}</td>
        <td>{{d.RealName}}</td>
        <td>{{d.Phone}}</td>
        <td>{{d.Products}}</td>
        <td>{{d.OriginalPrice}}</td>
        <td>{{d.PayPrice}}</td>
        <td>{{d.CreateDate|to_date}}</td>
        <td><button class="btn btn-primary y-btn" onclick="shipments()">发货</button></td>
    </tr>
    {{/each}}
</script>

<script type="text/html" id="tp-order-detail">
    <div id="layre-order-detail" style="padding:10px">
        <div class="panel" id="tem">
            <div class="panel-heading">订单详细</div>
            <div class="panel-body">
                <table class="table table-bordered">
                    <thead>
                        <tr>
                            <th>ID</th>
                            <th>订单号</th>
                            <th>订单状态</th>
                            <th>创建时间</th>
                            <th>供货商名称</th>
                            <th>支付类型 </th>
                            <th>付款时间</th>
                            <th>发货时间</th>
                            <th>收货时间 </th>
                            <th>物流公司名称</th>
                            <th>物流公司编码</th>
                            <th>物流单号</th>
                            <th>收货真实姓名</th>
                            <th>收货联系方式</th>
                            <th>邮编号码 </th>
                            <th>收货地址省份</th>
                            <th>收货地址城市</th>
                            <th>收货地址区/县 </th>
                            <th>收货地址明细</th>
                            <th>产品数量</th>
                            <th>原价总额 </th>
                            <th>支付总额</th>
                            <th>自动关闭订单时间</th>
                        </tr>
                    </thead>
                    <tbody></tbody>
                </table>
            </div>
        </div>
    </div>
</script>

<script type="text/html" id="tem-shipments">
    <div style="margin:20px" class="form-horizontal" id="delivery">
        <div class="form-group">
            <label class="col-sm-4">订单号</label>
            <div class="col-md-6 col-sm-1">
                <input type="text" class="form-control" data-form="OrderNo" placeholder="订单号" value="{{OrderNo}}" maxlength="30">
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-4">快递号</label>
            <div class="col-md-6 col-sm-10">
                <input type="text" class="form-control" data-form="LogisticsNo" placeholder="快递号" value="{{LogisticsNo}}" maxlength="30">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-4">物流公司编号</label>
            <div class="col-md-6 col-sm-10">
                <input type="text" class="form-control" data-form="LogisticsCode" placeholder="物流公司编号" value="{{LogisticsCode}}" maxlength="30">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-4">物流公司名称</label>
            <div class="col-md-6 col-sm-10">
                <input type="text" class="form-control" data-form="LogisticsName" placeholder="物流公司名称" value="{{LogisticsName}}" maxlength="30">
            </div>
        </div>

        <div class="form-group">
            <div class="col-sm-offset-4 col-sm-7">
                <button type="button" id="btn-submit" class="btn btn-primary">确定</button>
            </div>
        </div>
    </div>

</script>


<script type="text/html" id="det-temp">
    {{set  d=list}}
    <tr>
        <td>{{d.Id}}</td>
        <td>{{d.OrderNo}}</td>
        {{if d.Status==1}}
        <td>待付款</td>
        {{else if d.Status==2}}
        <td>待发货</td>
        {{else if d.Status==3}}
        <td>待收货</td>
        {{else if d.Status==4}}
        <td>待评价</td>
        {{else if d.Status==5}}
        <td>已完成</td>
        {{/if}}
        <td>{{d.CreateDate}}</td>
        <td>{{d.SupplierName}}</td>
        <td>{{d.PayName}}</td>
        <td>{{d.PayDate|to_date}}</td>
        <td>{{d.DeliveryDate|to_date}}</td>
        <td>{{d.TakeDeliveryDate|to_date}}</td>
        <td>{{d.LogisticsName}}</td>
        <td>{{d.LogisticsCode}}</td>
        <td>{{d.LogisticsNo}}</td>
        <td>{{d.RealName}}</td>
        <td>{{d.Phone}}</td>
        <td>{{d.PostCode}}</td>
        <td>{{d.Province}}</td>
        <td>{{d.City}}</td>
        <td>{{d.Area}}</td>
        <td>{{d.AddressDetai}}</td>
        <td>{{d.Products}}</td>
        <td>{{d.OriginalPrice}}</td>
        <td>{{d.PayPrice}}</td>
        <td>{{d.AutoCloseDate|to_date}}</td>
    </tr>

</script>

<script type="text/javascript">
    $(function () {
        function _LoadData() {
            var parm = $(".view-search").getFormData();
            $("#table").ajaxPageTable("buycustomergradeorder/list", parm, function (d) {
              
                $("#upgrade>#table>tbody").append(template("tp-table", {
                    list: d
                }));
            })
        }
        _LoadData();//初启化
        $("#query").focus(function () { //搜索按钮
            $("#query").keydown(function (e) {
                if (e.keyCode == 13) {
                    _LoadData();
                }
            })
        })
        $("#btn-search").click(function () { //搜索按钮
            _LoadData();
        })


    })

    var ValidEvent;
    var formValidInit = function () {
        var formValidData = [
            {
                key: "OrderNo",
                datatype: "*",
                nullmsg: "不能为空哦",
                errormsg: "不能为空哦"
            },
            {
                key: "LogisticsNo",
                datatype: "*",
                nullmsg: "不能为空哦",
                errormsg: "不能为空哦"
            },
            {
                key: "LogisticsCode",
                datatype: "*",
                nullmsg: "不能为空哦",
                errormsg: "请正确输入！"
            },
            {
                key: "LogisticsName",
                datatype: "*",
                nullmsg: "不能为空哦",
                errormsg: "请正确输入！"
            },

        ];
        ValidEvent = $("#delivery").formValid(formValidData);
    }
    var inintData = {
        OrderNo: "",
        LogisticsNo: "",
        LogisticsCode: "",
        LogisticsName: "",
    };

    function shipments() {  //弹出发货面板
        $.layrePage({  //弹出
            area: ["50%", "400px"],
            title: "-发货-",
            offset: "6px",
            content: template("tem-shipments", {inintData})

        });
        delivery()
    }

    function delivery() {   //确定发货      
        formValidInit()
        $("#delivery").on("click", "#btn-submit", function () { //保存按钮有添加和编辑
            if (!ValidEvent.check()) { return; }          
            $("#delivery").ajaxFormSubmit("buycustomergradeorder/shipments", {
                pass: function (d) {
                  
                    $.msgSucceed(d.Errmsg);
                    return
                },
                error: function (d) {
                    console.log(d)
                    $.msgFall(d.Errmsg);
                }
            })
            return
        });
    }


    function openDetail(o) {  //弹出升级会员订单详情
        $.layrePage({  //弹出
            area: ["90%", "800px"],
            title: "-",
            offset: "6px",
            content: template("tp-order-detail", {})
        });

        $.http.json("buycustomergradeorder/find", { OrderNo: o }, { //发出请求
            pass: function (d) {
                console.log(d);
                $("#layre-order-detail #tem table>tbody").append(template("det-temp", { //订单详情
                    list: d
                }));
            },
            error: function (d) {
                console.log(d)
            }
        })

    }
</script>